home *** CD-ROM | disk | FTP | other *** search
/ Beginning Mac Programming / Beginning Mac Programming.bin / pc / Open Me for REALbasic 3 / REALbasic 3.2 / Example Projects / Techniques / Examples by Thomas Tempelmann / TT's Icons-Plugin / Source Code (CW Pro 3) / Plugin Source.cpp < prev   
Encoding:
C/C++ Source or Header  |  1999-06-25  |  3.0 KB  |  130 lines

  1. /*
  2.  * REALbasic-Plugin for converting Icons to RB-Pictures
  3.  *
  4.  * This code is freeware, you may use and extend it as you like.
  5.  *
  6.  * The enclosed project file was created using CodeWarrior Pro 3.
  7.  *
  8.  * It was written on April 6, 99 by Thomas Tempelmann, <http://www.tempel.org/rb/>
  9.  *
  10.  * Enjoy and contribute!
  11.  */
  12.  
  13. #include <string.h>
  14. #include "rb_plugin.h"
  15.  
  16. static void copyBytes (const char* src, Ptr dest, short n)
  17. {
  18.     while (n--) {
  19.         *dest++ = *src++;
  20.     }
  21. }
  22.  
  23. static REALpicture IconToPict (REALstring iconData, long depth, long size)
  24. {
  25.     REALpicture p;
  26.     GWorldPtr world;
  27.     Rect r;
  28.     SetRect (&r, 0, 0, size, size);
  29.     NewGWorld (&world, depth, &r, nil, nil, 0);
  30.     PixMapHandle pm = GetGWorldPixMap (world);
  31.     Ptr dest = GetPixBaseAddr (pm);
  32.     const char* src = iconData->CString();
  33.     for (int i = 0; i < size; i++) {
  34.         short n = (size/8)*depth;
  35.         copyBytes (src, dest, n);
  36.         src += n;
  37.         dest += (*pm)->rowBytes & 0x3FFF;
  38.     }
  39.     p = REALBuildPictureFromGWorld (world, true);
  40.     //DisposeGWorld(world);
  41.     return p;
  42. }
  43.  
  44.  
  45.  
  46. /*
  47. static GWorldPtr REALPictToGWorldPtr (REALpicture pic, const Rect &rBounds)
  48. // this routine is taken from QTEffect.cpp out of the Plugin SDK v3
  49. {
  50.     GWorldPtr gw;
  51.     CGrafPtr oldPort;
  52.     GDHandle oldDevice;
  53.  
  54.     GetGWorld(&oldPort, &oldDevice);
  55.  
  56.     NewGWorld(&gw, 16, &rBounds, nil, nil, 0);
  57.     LockPixels(GetGWorldPixMap(gw));
  58.  
  59.     SetGWorld(gw, nil);
  60.     EraseRect(&rBounds);
  61.     REALDrawPicturePrimitive(pic, &rBounds, false);
  62.  
  63.     SetGWorld(oldPort, oldDevice);
  64.  
  65.     return gw;
  66. }
  67. */
  68.  
  69. /*
  70. void (REALpicture pic1)
  71. {
  72.     REALpictureDescription description;
  73.     int w, h;
  74.     Rect r;
  75.  
  76.     REALLockPictureDescription(pic1, &description);
  77.  
  78.     w = description.width;
  79.     h = description.height;
  80.     SetRect(&r, 0, 0, w, h);
  81.  
  82.     if (description.pictureType == pictureMacintoshGWorld) {
  83.         REALLockObject((REALobject) pic1);
  84.         fGW1 = (GWorldPtr) description.pictureData;
  85.     } else {
  86.         data->pic1 = nil;
  87.         data->fGW1 = REALPictToGWorldPtr(pic1, r);
  88.     }
  89.  
  90.     NewGWorld(&data->fDest, 16, &r, nil, nil, 0);
  91.     data->destPicture = REALBuildPictureFromGWorld(data->fDest, true);
  92.  
  93.     QTEffects_SetUpEffectSequence(data, data->fDest, GetGWorldDevice(data->fDest));
  94. }
  95. */
  96.  
  97. /*
  98. static REALstring PictToIcon (REALpicture pictData, long depth, long size)
  99. {
  100.     GWorldPtr world;
  101.     Rect r;
  102.     SetRect (&r, 0, 0, size, size);
  103.     NewGWorld (&world, depth, &r, nil, nil, 0);
  104.     PixMapHandle pm = GetGWorldPixMap (world);
  105.     Ptr dest = GetPixBaseAddr (pm);
  106.     const char* src = iconData->CString();
  107.     for (int i = 0; i < size; i++) {
  108.         short n = (size/8)*depth;
  109.         copyBytes (src, dest, n);
  110.         src += n;
  111.         dest += (*pm)->rowBytes & 0x3FFF;
  112.     }
  113.     return REALBuildPictureFromGWorld (world, true);
  114. }
  115. */
  116.  
  117. REALmethodDefinition methods[] = {
  118.     { (REALproc)IconToPict, nil, "IconToPict(icon as String, bitDepth as Integer, size as Integer) as Picture" },
  119. //    { (REALproc)PictToIcon, nil, "PictToIcon(pict as Picture, bitDepth as Integer, size as Integer) as String" },
  120. };
  121.  
  122. short pluginMethods = sizeof(methods) / sizeof(REALmethodDefinition);
  123.  
  124. void PluginEntry (void)
  125. {
  126.     for (int i = 0; i < pluginMethods; ++i) {
  127.         REALRegisterMethod (&methods[i]);
  128.     }
  129. }
  130.